<%--
  Created by IntelliJ IDEA.
  User: 伟
  Date: 2019/6/10
  Time: 10:14
  To change this template use File | Settings | File Templates.
--%>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/7/16 0016
  Time: 上午 10:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<html>
<head>
    <title>Title</title>
    <script src="../../js/jquery-3.3.1.min.js" charset="utf-8"></script>
    <script src="../../js/cookie/jquery.cookie.js" charset="utf-8"></script>
    <script src="../../layui-v2.2.5/layui/layui.js" charset="utf-8"></script>
    <link rel="stylesheet" href="../../layui-v2.2.5/layui/css/layui.css" media="all">
    <style>
        .layui-table-view{
            margin-bottom: 120px;
        }
    </style>
</head>
<body>
<br><br><br>
<div>
    <button class="layui-btn" id="add" >添加标签</button>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right;margin-right: 100px"  href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i>
    </a>
</div>
<div class="layui-form">
    <form class="layui-form" action="">
        <input type="hidden" id="callIcon" value="${record.commodityId}" name="commodityId">
        <table class="layui-table" >
            <thead>
            <tr>

                <th>标签内容</th>
                <th>标签序号</th>

               <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach items="${pageUtil.list}" var="rl">
                <tr>

                    <td>${rl.content}</td>
                    <td>${rl.number}</td>

                    <td style="width: 180px;">
                        <button type="button" class="layui-btn" onclick="update('${rl.id}');">修改</button>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <button type="button" class="layui-btn layui-btn-danger" onclick="delProduct('${rl.id}');">删除</button>
                    </td>

                </tr>
            </c:forEach>
            </tbody>
        </table>
    </form>


    <div id="page"></div>
    <script>
        layui.use('laypage', function(){
            var laypage = layui.laypage;
            laypage.render({
                elem: 'fenye'
                ,count: ${pageUtil.totalRows}
                ,limit:10//数据总数，从服务端得到
                ,curr:${pageUtil.currentPage}
                ,hash:true
                ,jump: function(obj, first){
                    //obj包含了当前分页的所有参数，比如：
                    console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据
                    console.log(obj.limit); //得到每页显示的条数
                    //首次不执行
                    if(!first){
                        window.location.href="/shop/brandLabel?page="+obj.curr+"&limit="+obj.limit;
                    }
                }
            });
        });
    </script>
</div>
<script>
    layui.use('layer', function(){
        var layer = layui.layer;
        $(document).on('click','#add',function(){
            layer.open({
                type: 2,
                area: ['80%', '80%'],
                title: '添加商品标签',
                offset: '20px',
                shadeClose:true,
                content: "/shop/displayUpdate?commodityId=${commodityId}",
                end:function () {
                    console.log("页面要刷新");
                    window.location.reload();
                }
            });
        });
    });
    /*修改标签*/
    function update(id) {
        layer.open({
            type: 2,
            area: ['80%', '80%'],
            offset: '20px',
            title: '修改标签',
            shadeClose:true,
            content: '/shop/displayUpdate?id='+id,
            end:function () {
                console.log("页面要刷新");
                window.location.reload();
            }
        });
    }

    /*删除标签*/
    function delProduct(id) {
        $.ajax({
            url:'/shop/deleteTags',
            type:'POST', //GET
            async:true,    //或false,是否异步
            data:{
                id:id,
            },
            timeout:5000,    //超时时间
            dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
            success:function(data){
                console.log(data);
                if (data.code=='000000'){
                    window.location.reload();
                    // 获得frame索引
                }else {
                    data.code("删除失败");
                }
            },
            error:function(xhr,textStatus){
                console.log('错误')
                console.log(xhr)
                console.log(textStatus)
            },
            complete:function(){
                //console.log('结束')
            }
        })
    }

</script>
</body>
</html>

